<template>
  <view class="furniture-list">
    <!-- 完全去除自定义导航栏 -->
    <view class="header-section">
      <!-- 只使用Logo图片 -->
      <image 
        class="logo" 
        src="@/static/images/logo.png" 
        mode="aspectFit"
        :draggable="false"
        @error="handleLogoError"
      />
      <!-- 下方文字描述 -->
      <view class="platform-name">红木家具交易平台</view>
    </view>
    
    <!-- 商品列表 -->
    <uni-list>
      <uni-list-item 
        v-for="item in goodsData" 
        :key="item._id"
        :title="item.name"
        :note="formatNote(item)"
        :thumb="item.cover"
        clickable
        @click="navToDetail(item._id)"
      >
        <template v-slot:footer>
          <view class="item-footer">
            <text class="price">¥{{ item.price/100 }}</text>
            <text class="material-tag">{{ item.material }}</text>
          </view>
        </template>
      </uni-list-item>
    </uni-list>
    
    <!-- 浮动添加按钮 -->
    <view class="add-button">
      <uni-fab 
        horizontal="right"
        vertical="bottom"
        @fabClick="navToAdd"
      ></uni-fab>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      goodsData: []
    }
  },
  onLoad() {
    this.loadGoods()
  },
  methods: {
    formatNote(item) {
      return `${item.category} | ${item.material}`
    },
    navToDetail(id) {
      uni.navigateTo({
        url: `/pages/furniture/detail?id=${id}`
      })
    },
    navToAdd() {
      uni.navigateTo({
        url: '/pages/furniture/add'
      })
    },
    async loadGoods() {
      try {
        const db = uniCloud.database()
        const res = await db.collection('goods').get()
        this.goodsData = res.result.data
      } catch (e) {
        console.error('加载商品失败:', e)
        this.goodsData = [
          {
            _id: "1",
            name: "紫檀木雕花沙发",
            price: 1288000,
            category: "沙发",
            material: "紫檀",
            cover: "https://via.placeholder.com/150"
          },
          {
            _id: "2",
            name: "黄花梨餐桌",
            price: 980000,
            category: "餐桌椅",
            material: "黄花梨",
            cover: "https://via.placeholder.com/150"
          }
        ]
      }
    },
    handleLogoError(e) {
      console.error('Logo加载失败:', e)
    }
  }
}
</script>

<style scoped>
/* ===== 完全匹配图片中的头部 ===== */
.header-section {
  background-color: #5c3c1c;
  padding: 25px 0 15px;
  border-bottom-left-radius: 30px;
  border-bottom-right-radius: 30px;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  margin-bottom: 15px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

/* Logo样式 - 确保只有图片中的"金牌涛" */
.logo {
  width: 110px;
  height: 110px;
  border-radius: 50%;
  background-color: white;
  padding: 5px;
  border: 3px solid #e8c39e;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  
  /* 禁止图片拖拽 */
  user-select: none;
  -webkit-user-drag: none;
  -webkit-user-select: none;
}

/* 平台名称样式 */
.platform-name {
  color: #e8c39e; /* 金色文字 */
  font-size: 16px;
  margin-top: 15px;
  text-align: center;
  font-weight: 500;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

/* ===== 商品列表样式 ===== */
.uni-list {
  margin-top: 0;
  background-color: transparent;
}

.uni-list-item {
  margin: 10px 15px;
  border-radius: 15px;
  overflow: hidden;
  background-color: white;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.uni-list-item:active {
  transform: scale(0.98);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}

.item-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 8px;
  padding: 0 10px;
}

.price {
  color: #d42828;
  font-weight: bold;
  font-size: 18px;
}

.material-tag {
  background: #e8c39e;
  color: #5c3c1c;
  border-radius: 4px;
  padding: 3px 10px;
  font-size: 12px;
}

/* ===== 全局样式 ===== */
.furniture-list {
  background: #f8f3ed;
  min-height: 100vh;
}

.add-button {
  position: fixed;
  right: 20px;
  bottom: 30px;
  z-index: 1000;
}

/* 响应式设计 */
@media (min-width: 768px) {
  .logo {
    width: 130px;
    height: 130px;
  }
  
  .platform-name {
    font-size: 18px;
  }
  
  .uni-list {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
    padding: 0 15px;
  }
  
  .uni-list-item {
    margin: 0;
  }
}
</style>